package com.distributer.product.request;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.distributer.product.model.DistributerProduct;
import com.distributer.product.service.DistributerProductService;

/**
 * 产品更新请求
 * 
 * @author Administrator
 *
 */
public class ProductUpdateRequest implements Request {

	private static final Logger LOGGER = LoggerFactory.getLogger(ProductUpdateRequest.class);

	private final DistributerProduct distributerProduct;

	private final DistributerProductService distributerProductService;

	public ProductUpdateRequest(DistributerProduct distributerProduct, DistributerProductService distributerProductService) {
		this.distributerProduct = distributerProduct;
		this.distributerProductService = distributerProductService;
	}

	@Override
	public void process() {
		// 删除缓存
		distributerProductService.removeProductInfoFromCache(distributerProduct.getProductCode());
		// 更新数据库
		distributerProductService.update(distributerProduct);
		LOGGER.info("产品编码： " + distributerProduct.getProductCode() + "更新成功！");
	}

	@Override
	public String getJbProductCode() {
		return this.distributerProduct.getProductCode();
	}

}
